
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
import os

class Application(Flask):
    def __init__(self, import_name, static_folder, template_folder):
        super(Application, self).__init__(import_name, static_folder=static_folder, template_folder=template_folder)
        if 'ops_config' in os.environ:
            self.config.from_pyfile('config/%s_setting.py' % os.environ['ops_config'])
        else:
            self.config.from_pyfile('config/local_setting.py')
        db.init_app(self)


db = SQLAlchemy()
app = Application(__name__, static_folder=os.getcwd()+'/web/static', template_folder=os.getcwd()+'/web/templates')
manager = Manager(app)

'''
全局函数模板
'''
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl, 'buildUrl')
app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')
